<%#
kind: snippet
name: ansible_tower_callback_service
model: ProvisioningTemplate
snippet: true
description: |
  The content of a systemd service for running Ansible Tower / AWX callback script one-time.
  Used in the ansible_provisioning_callback snippet for systemd enabled systems.
-%>
[Unit]
Description=Provisioning callback to Ansible Tower
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
<% if host_param('ansible_extra_vars') -%>
ExecStart=/usr/bin/curl -k -s -H 'Content-Type: application/json' --data '{"host_config_key":"<%= host_param('ansible_host_config_key') %>", "extra_vars": <%=host_param('ansible_extra_vars') %>}' <%= host_param('ansible_tower_api_url') %>/job_templates/<%= host_param('ansible_job_template_id') %>/callback/
<% else -%>
ExecStart=/usr/bin/curl -k -s --data "host_config_key=<%= host_param('ansible_host_config_key') -%>" <%= host_param('ansible_tower_api_url') -%>/job_templates/<%= host_param('ansible_job_template_id') -%>/callback/
<% end -%>
ExecStartPost=/usr/bin/systemctl disable ansible-callback

[Install]
WantedBy=multi-user.target
